--
-- Author: mm
-- Date: 2018-04-05 15:05:18
--
-- LionHornController
-- 狮心号角相关

local LionHornRoundStartPanel = import("..views.LionHornRoundStartPanel")
local LionHornRoundEndView = import("..views.LionHornRoundEndView")

local fileName = string.getModeName(...)
local ClassRef = class(fileName, app.mvc.ControllerBase)

function ClassRef:ctor(data)
    self.super.ctor(self, data)
end

function ClassRef:init()
    self._model = app:getInst("NewActivityDungeonsModel")
end

function ClassRef:removeListeners()
    self.super.removeListeners(self)
end

function ClassRef:onEvent(eventName, data)
    if eventName == "onMapChanged" then
        if self._model:isLionHornMap() then
            self._model:reqStartLionHorn()
        end
    end
end

function ClassRef:listEvent()
    return {
        "onMapChanged"
    }
end


-- function ClassRef:openView(data)
--     if cc.isDead(self._view) then
--         self._view = .new()
--         self._view:onCloseView(handler(self, self.closeView))
--         self._view:onClearView(handler(self, self.clearView))
--         self._view:onOperate(handler(self, self.onOperate))
--         self:addChild(self._view, data)
--     end
--     self._view:show()
-- end

-------------------------------------------------------
function ClassRef:showLionHornTips( data ) -- 提示
    local view = LionHornTipsPanel.create( nil, data )
    view:setPosition( cc.p( display.width/2 , display.height/2 ) )
    view:onCloseView(function() self:removeChild(view, {isFade=false}) end)
    view:onOperate(handler(self, self.onOperate))
    view:setData( data )
    self:addChild(view, { isFade = false })
end


-------------------------------------------------------
function ClassRef:showLionHornRoundStart( data, lionHeartUserInfoList ) -- 回合开始
    local view = LionHornRoundStartPanel.create( nil, data )
    view:setPosition( cc.p( display.width/2 , display.height/2 ) )
    view:onCloseView(function() self:removeChild(view, {isFade=false}) end)
    view:onOperate(handler(self, self.onOperate))
    view:setData( data )
    self:addChild(view , { isFade = false })

    FieldManager:buildLionHornCharacters(lionHeartUserInfoList)
end

-------------------------------------------------------
function ClassRef:openRoundEndView(data)
    if nil == self._roundEndView then
        self._roundEndView = LionHornRoundEndView.new()
        self._roundEndView:onCloseView(handler(self, self.closeRoundEndView))
        self._roundEndView:onClearView(handler(self, self.clearRoundEndView))
        self._roundEndView:onOperate(handler(self, self.onOperate))
    end
    self:addChild(self._roundEndView, { isFade = false })
    self._roundEndView:refreshContent( data )
end
function ClassRef:closeRoundEndView(data)
    if self._roundEndView then
        self:removeChild(self._roundEndView, data)
        self:clearRoundEndView()
    end
end
function ClassRef:clearRoundEndView()
    if self._roundEndView then
        self._roundEndView = nil
    end
end
-- 返回 roundEndView 可见性
function ClassRef:isRoundEndViewShown()
    local isShown = false
    if not cc.isDead(self._roundEndView) then
        isShown = self._roundEndView:isVisible()
    end
    return isShown
end


-------------------------------------------------------
function ClassRef:onOperate(op, data)
    -- print(" ------------->>>>>> LionHornController:onOperate op = " .. op)
    if op == "roundStart" then -- 回合开始
        self._model:reqLionHornRoundStart()
    elseif op == "roundRwardEnd" then -- 结算UI处理完毕
        self._model:reqStartLionHorn()
    end
end

return ClassRef
